package br.com.unitunes.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.AssociationOverrides;
import javax.persistence.AssociationOverride;
import javax.persistence.JoinColumn;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity(name = "MIDIA_COMPRADA")
@AssociationOverrides({
	@AssociationOverride(name = "usuario", 
		joinColumns = @JoinColumn(name = "USUARIO_ID")),
	@AssociationOverride(name = "midia", 
		joinColumns = @JoinColumn(name = "MIDIA_ID")) })
public class MidiaComprada {

	@EmbeddedId
	private MidiaCompradaId id = new MidiaCompradaId();
		
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "DATA_CREATE", nullable = true)
    private Date dataCreate;

    @Column(name = "VALOR_PAGO")
    private Double valorPago = new Double(0);
    
	@Transient
	public Usuario getUsuario() {
		return getId().getUsuario();
	}
 
	public void setUsuario(Usuario usuario) {
		getId().setUsuario(usuario);
	}
 
	@Transient
	public Midia getMidia() {
		return getId().getMidia();
	}
 
	public void setMidia(Midia Midia) {
		getId().setMidia(Midia);
	}

	public MidiaCompradaId getId() {
		return id;
	}

	public void setId(MidiaCompradaId id) {
		this.id = id;
	}

	public Date getDataCreate() {
		return dataCreate;
	}

	public void setDataCreate(Date dataCreate) {
		this.dataCreate = dataCreate;
	}

	public Double getValorPago() {
		return valorPago;
	}

	public void setValorPago(Double valorPago) {
		this.valorPago = valorPago;
	}    
	
    @PrePersist
    protected void onCreate() {
    	dataCreate = new Date();
    }

}
